package com.thoughtmechanix.organization.controller;

import com.thoughtmechanix.organization.model.Organization;
import com.thoughtmechanix.organization.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "v1/organizations")
public class OrganizationServiceController {
    @Autowired
    private OrganizationService organizationService;

    @GetMapping(value = "/{organizationId}")
    public Organization getOrganization(@PathVariable("organizationId") String organizationId){
        return organizationService.getOrg(organizationId);
    }

    @PutMapping(value = "/{organizationId}")
    public void updateOrganization(@PathVariable("organizationId") String organizationId,
                                   @RequestBody Organization org){
        organizationService.updateOrg(org);
    }

    @PostMapping(value="/{organizationId}")
    public void saveOrganization(@RequestBody Organization org) {
        organizationService.saveOrg( org );
    }

    @DeleteMapping(value="/{organizationId}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deleteOrganization( @PathVariable("orgId") String orgId,  @RequestBody Organization org) {
        organizationService.deleteOrg( org );
    }
}
